(function() {
	Path.on("/main/__basename__.html", function(_current_location) {
		// 拉取所有banner
		coAjax.get(public_api.banner.get.all, function(result) {
			App.set("$Cache.main.ad.banner_list", result);
		});
	});
	// 上传图片
	App.set("$Event.main.ad.upload", function() {
		var file = this.files[0];
		if (file) {
			var upload_id_photo_dtd = new $.Deferred();
			App.set("$Cache.main.ad.banner.isadding", true);
			$.when(upload_image(file, upload_id_photo_dtd)).then(function(image_url) {
				App.set("$Cache.main.articleedit.data.imgurl", image_url);
				coAjax.post(public_api.banner.create, { url: image_url }, function(result) {
					App.push("$Cache.main.ad.banner_list", result);
					alert("success", "上传成功")
				});
				App.set("$Cache.main.ad.banner.isadding", false);
			});
		};
	});
	// 删除图片
	App.set("$Event.main.ad.removeAd", function(e, vm) {
		myConfirm("确定要删除这张图片吗？", function() {
			coAjax.delete(public_api.banner.remove + vm.get("_id"), function(result) {
				vm.remove();
				alert("success", "删除成功");
			});
		});
	});
}());
